var userInfoApp = angular.module("userInfoApp", []);
userInfoApp.controller("userInfoController", function($scope, $rootScope, $timeout,$location, scCodeService, commonService, jsonToStr,pubFun) {
    $rootScope.showLogin = localStorage.getItem("isLogin")=="true" ? false : true;
    $rootScope.state = 0;
    //退出登录
    $scope.userInfoPhone = localStorage.getItem("phone").replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')||"";
    var userId = localStorage.getItem("userId");
    var token = localStorage.getItem("token");
    var account = localStorage.getItem("account");
    var openId = localStorage.getItem("openId");

    // 
    $scope.outClick = false;
    $scope.logOut = function() {
        $scope.setConfirmEx()
    };
    //确定退出
    $rootScope.sureLogOut = function() {
        $scope.outClick = true;
        $scope.confirmExHide();
        var postData = {
            "source": mainConfig.source,
            // "userId":userId,
            // "token":token,
            "bindType": "1",
            "account": userId,
            "jPushRegId": account,
            "merchantCode": mainConfig.merchantCode
        };
        scCodeService.unlockUser(postData).then(function(data) {
            // alert(JSON.stringify(data));
            if (data.code == "200") {
                localStorage.clear();
                localStorage.setItem("openId",openId);
                $location.path("index_")
            } else {
                $scope.outClick = false;
            }
        });
    };
});
userInfoApp.controller("collectController", function($scope, $http,$rootScope, scCodeService, $location, $stateParams, commonService, jsonToStr,pubFun) {
    $scope.showNav = true;
    $scope.showDele = false;
    $scope.operate = "编辑";
    $scope.showNoneCollect=false;
    $scope.collectList=[];
    //点击“编辑”、“返回”
    $scope.edit = function() {
        $scope.showNav = $scope.showNav == true ? false : true;
        $scope.showDele = $scope.showDele == true ? false : true;
        $scope.operate = $scope.operate == "编辑" ? "返回" : "编辑";
    };
    // 获取收藏列表

    $scope.getCollectList = function() {
        document.getElementById("loadingToast1").style.display = "block";
        // 模拟数据
        $scope.collectList =[];/* [{
            "stationName": "环球中心充电站",
            "stationAddr": "环球中心E2地下停车场"
        }, {
            "stationName": "环球中心充电站2",
            "stationAddr": "环球中心E2地下停车场2"
        }, {
            "stationName": "环球中心充电站3",
            "stationAddr": "环球中心E2地下停车场3"
        }, ];*/
        var postData = {
            userId:localStorage.getItem("userId"),
            pageNo:"1"
        };
        scCodeService.collectionStationList(postData).then(function(data){
            if(data.code=="200"){
                document.getElementById("loadingToast1").style.display = "none";
                angular.forEach(data.data, function(value, index){
                    $scope.collectList.push(value);
                });
                if($scope.collectList=="" || $scope.collectList.length==0){
                    document.getElementById("loadingToast1").style.display = "none";
                    $scope.showNoneCollect=true;
                }
            }else{
                document.getElementById("loadingToast1").style.display = "none";
            }
        });

    };
    //删除一条收藏
    $scope.remove = function(data,index) {
        document.getElementById("loadingToast1").style.display = "block";
        $rootScope.collectionStation(data.stationId,"1").then(function(){
            document.getElementById("loadingToast1").style.display = "none";
            $scope.collectList.splice(index,1);
            $scope.showNoneCollect = globalFun.isEmptyObj($scope.collectList)?true:false;
        })
    };
    // 点击导航
    $scope.naviGation = function(stationId){
        //$rootScope.getStationDetail();
        pubFun.getStationDetail(stationId).then(function (data) {
            window.location.href = "https://map.qq.com/m/mqq/nav/eword="+data.address+"&epointx="+data.longitude+"&epointy="+data.latitude+"?referer=myapp&key=P44BZ-LANRX-D6I46-ZTXJL-OHJT2-LKBR3";
        });
                
    };
    // 进入我的收藏执行的方法
    $scope.getCollectList();
    //点击进入站点详情
    $scope.goToStation=function (stationId) {
        window.location.href=mainConfig.hostUrl+'index.html?#/stateDetail/'+stationId+'/0';
    }
});
